<?php
@session_start();

include_once("../lib/functions.php");
getProjectRootPath();
//die("DOC-ROOT: ".$_SERVER['DOCUMENT_ROOT']);
require_once($_SERVER['DOCUMENT_ROOT']."/updates/PostActions.php");
require_once($_SERVER['DOCUMENT_ROOT']."/updates/ReadNotifications.php");

$actionType=0;

//echo "<pre>";
//print_r($_POST);
//echo "</pre>";
//die();
//
if(isset($_POST["actiontype"])){
    if(trim($_POST["actiontype"])!="" || strtolower(trim($_POST["actiontype"]))!="none" ){
        //mean there is some action to perform
        $actionType=trim($_POST["actiontype"]);   
        $notificationType=""; 
        $loggedInId=0;
        try {            
            //try to read all psted values
            if (isset($_SESSION["Allyfolio_User_ID"]) && !empty($_SESSION["Allyfolio_User_ID"])) {
                $loggedInId = trim($_SESSION["Allyfolio_User_ID"]);
            }
            if (isset($_POST["notificationType"]) && !empty($_POST["notificationType"])) {
                $notificationType = trim($_POST["notificationType"]);
            }
            if(strlen($notificationType)<=0){
                $notificationType="friend_req_found";
            }
            
            //echo $loggedInId." action type: ".$actionType;
                           
            if($loggedInId >0 ){            
                switch($actionType){
                    case 'get_feedsnotification': //like
                    case 'get_allnotifications': //like                
                        try {
                            
                            $objReadNotification=new Notifications();
                            $notificationsJsonData=$objReadNotification->getNewsFeedNotifications($loggedInId,true);
                            echo $notificationsJsonData;
                            //die("get_notification");
                        }
                        catch(Exception $ex){
                            $oLog->writeException('readNotifications.php: getNewsFeedNotifications():: \t'. $ex->getMessage(). "\n");
                            echo responseWithErrorCode("400",$ex->getMessage());
                        }
                        break;
                    /*case 'get_allnotifications': //like                
                        try {
                            
                            $objReadNotification=new Notifications();
                            $notificationsJsonData=$objReadNotification->getNotifications($loggedInId,true);
                            echo $notificationsJsonData;
                            //die("get_notification");
                        }
                        catch(Exception $ex){
                            $oLog->writeException('readNotifications.php: getNotifications():: \t'. $ex->getMessage(). "\n");
                            echo responseWithErrorCode("400",$ex->getMessage());
                        }
                        break;
                    */
                    case 'get_minenotifications':
                        try {
                            
                            $objReadNotification=new Notifications();
                            $notificationsJsonData=$objReadNotification->getMineNotifications($loggedInId,$notificationType);
                            echo $notificationsJsonData;
                            //die("get_notification");
                        }
                        catch(Exception $ex){
                            $oLog->writeException('readNotifications.php: getMineNotifications():: \t'. $ex->getMessage(). "\n");
                            echo responseWithErrorCode("400",$ex->getMessage());
                        }
                        break;
                    
                 }
            }
            else{
                $actionRes=$postAction->Failed_For_Invalid_Session;
                echo $actionRes["msg"];
            }
        
        }
        catch(Exception $ex){
            die("Exception in readNotifications.php".$ex->getMessage());
        } 
    }
}
?>